
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json

import requests

if __name__ == "__main__":
    url = "http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx"
    param = {
        'op': 'keyword',
    }
    data = {
        'cname':'',
        'pid':'',
        'keyword': '椒江',
        'pageIndex': 1,
        'pageSize': 10,
    }

    # UA伪装
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52'
    }
    response = requests.post(url, params=param, data=data, headers=headers)
    # 响应数据处理
    dic_obj = response.json()

    # 持久化存储
    fp = open('data/KFC.json', 'w', encoding='utf-8')
    # ensure_ascii=False 中文不适用默认的ascii码
    json.dump(dic_obj, fp, ensure_ascii=False)